home *** CD-ROM | disk | FTP | other *** search
- From: CompuWord@msn.com (Meiyu Lin)
- Subject: RE: Coding Standards for C++
- Date: 30 Jan 96 03:58:39 -0800
- References: <4dhuok$qpl@news3.digex.net>
- Message-ID: <00001a81+0000965d@msn.com>
- Path: news.msn.com!msn.com
- Newsgroups: comp.lang.c++
- Organization: The Microsoft Network (msn.com)
-
- How is the following sounds to you:
-
- c) In a similar way, the declaration of a function should be procceeded by a
- comment describing what the function or procedure does, and how it does it.
-
- d) Lower-case letters should be used for KEY WORDS and Mix-case letters
- should be used for VARIABLE NAMES.
-
- e) Variable names should be mnemonic of what they are used for.
-
- f) #define should be in all CAPITAL letters to emphasiz the fact that the
- symbol is a constant and not a variable.
-
- g) Spaces, tabs (set to 4 characters), and blank lines should be freely used.
-
- h) The following operators should be surounded by spaces, such as:
- arithmetic binary operators:
- multiplication, division, addition, subtraction, modulus : (*, /, +, -, %).
- assignment (=), equals operator (==), not equal (!=), less than
- (<), less than
- or equal to (<=), grater than or equal to (>=), left shift (<<),
- right shift (>>),
- assignment operators: +=, -=, *=, /=, %=, <<=, >>=, &=, ^=, |=.
- logic operators: &&, ||
- bit operators: &, |
-
- The following unary operators (--, ++, !, ~) should be precede by a space,
- commas (,) should be followed by a space.
-
- i) Multiple statements placed on a single line tend to get hidden
- should be
- avoided.
-
- j) Statements contained in a compound statement should be indented by 4
- spaces.
-
- k) If a statement will not fit on a line, it should be broken up
- as best possible
- put on 2 lines. The second line should be spaced over so that
- it it longer
- than the first.
-
- Example:
- void TheFunctionName() {int sum=0, j; sum=sum+j;printf("This is a
- very bad example never do anything like this");j++;}
-
- void TheFunctionName()
- {
- int sum = 0, j = 0;
-
- sum += j; /* sum = sum + j */
- printf ("This is a very long write statement ");
- printf ("and will not fit on a single line...\n");
- j++;
- }
-
- 2. Control statements:
- ╖ Statements which are executed as the result of an if, or the
- looping statement: while, do
- while, for should be indented by 4 spaces.
-
- ╖ If the statement to be executed is a compound statement then the {
- and } should be
- placed on a line by themselves and indented the same amount as the
- loop statement.
-
- void ObjectClassName::BlockExample ()
- {
- char buffer[80];
- int i, length;
- int sum = 0;
-
- /*
- ** This comment style will be used for long comments lines. It
- ** explains what are you doing in the following statements.
- */
-
- printf ("Enter up to 75 characters and contains a * symbol:\n\n");
- scanf ("%s", buffer);
-
- // Find the length of the input string.
- length = strlen (buffer);
-
- /* Search for the æ*Æ */
- for (i = 0; i < length; i++)
- {
- if (buffer[i] != '*')
- {
- printf ("%c", buffer[i]);
- ++sum;
- }
- else
- {
-
-
-
-
-
- /*
- ** Found the "*" print it out and break the for loop
- */
- printf ("\n A start in your input at position %3d.\n", sum+1);
- break;
- }
-
- // User's input doesn't contains a *
- if (i == length)
- printf ("You didnÆt input \"*\" as the string terminater\n");
- }
- }
-
-